﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WindowsFormsApplication1.Properties;
using System.IO;
using Microsoft.Win32;
using System.Net;

namespace WindowsFormsApplication1
{
    public partial class BKUEDITOR : Form
    {
        public BKUEDITOR()
        {
            InitializeComponent(); 
        }

        private void BKUEDITOR_Load(object sender, EventArgs e)
        {

            singleton = this;
            h.hTextbox(textBox1);
            h.hTextbox(textBox2);
            h.hTextbox(textBox3);
            h.hTextbox(this.debugBox);
            h.hTool(toolStrip1, "XML-Signatur").Click += (s, s1) =>
            {
                HTTPC h1 = new HTTPC();
                h1.seteCallback((d) => {

                    HTTPC.Procedure1 x = new HTTPC.Procedure1(() =>
                    {
                        new Check().setSig(d);
                    });
                    if (this.InvokeRequired) this.Invoke(x); else x();
                });              
                h1.xmlSig(textBox1.Text.Trim());
               
            };     


            h.hTool(toolStrip1, "CMS-Signatur").Click += (s, s1) =>            {
                HTTPC h1 = new HTTPC();
                h1.seteCallback((d) =>
                {

                    HTTPC.Procedure1 x = new HTTPC.Procedure1(() =>
                    {
                        new Check().setSig(d);
                    });
                    if (this.InvokeRequired) this.Invoke(x); else x();
                });
                h1.cmsSig(textBox1.Text.Trim());
            };    

            h.hTool(toolStrip1, "Signatur prüfen").Click += (s, s1) =>            {
                openFileDialog1.ShowDialog();
            };                     

            h.hTool(toolStrip1, "Null").Click += (s, s1) =>
            {
                HTTPC h1 = new HTTPC(); 
                h1.nullCmd();           
            };

            h.hTool(toolStrip1, "Personenbindung").Click += (s, s1) =>
            {
                HTTPC h1 = new HTTPC();
                h1.seteCallback((d) =>
                {

                    HTTPC.Procedure1 x = new HTTPC.Procedure1(() =>
                    {
                        new Check().setSig(d);
                    });
                    if (this.InvokeRequired) this.Invoke(x); else x();
                });
                h1.raw(Resources.personenbindung);
            }; 



        h.hTool(toolStrip2, "TestSignatur").Click += (s, s1) =>
            {
                Check c = new Check();
               // c.Show(); 
                //c.setSig(Resources.testxml);
                        
            };

        h.hTool(toolStrip2, "TestDaten").Click += (s, s1) =>
        {
            textBox1.Text = Resources.testString;
        };

        h.hTool(toolStrip3, "Send RAW").Click += (s, s1) =>
        {
            HTTPC h1 = new HTTPC();
            h1.seteCallback((d) =>
            {

                HTTPC.Procedure1 x = new HTTPC.Procedure1(() =>
                {
                    new Check().setSig(d);
                });
                if (this.InvokeRequired) this.Invoke(x); else x();
            });
            h1.raw(textBox1.Text.Trim());
        };

        h.hTool(toolStrip3, "RAW-Signatur").Click += (s, s1) =>
        {
            textBox1.Text = Resources.xmla +"test"+ Resources.xmlb;
        }; 
        
        h.hTool(toolStrip3, "DTD").Click += (s, s1) =>
        {
            textBox1.Text = Resources.xmla + "test" + Resources.xmlb;
            textBox1.Text = textBox1.Text.Replace(Resources.xmlheader, Resources.dtd); 
        };

        h.hTool(toolStrip3, "dtd-web").Click += (s, s1) =>
        {
            textBox1.Text = Resources.xmla + "test" + Resources.xmlb;
            textBox1.Text =  textBox1.Text.Replace(Resources.xmlheader,Resources.dtdweb);
        };

        h.hTool(toolStrip3, "dtd-knoppix").Click += (s, s1) =>
        {
            textBox1.Text = Resources.xmla + "test" + Resources.xmlb;
            textBox1.Text = textBox1.Text.Replace(Resources.xmlheader, Resources.knoppix);
        };
        h.hTool(toolStrip3, "dtd-virus").Click += (s, s1) =>
        {
            textBox1.Text = Resources.xmla + "test" + Resources.xmlb;
            textBox1.Text = textBox1.Text.Replace(Resources.xmlheader, Resources.testvirus);
        };
        h.hTool(toolStrip3, "xmlbombe").Click += (s, s1) =>
        {
            textBox1.Text = Resources.xmla + "test" + Resources.xmlb;
            textBox1.Text = textBox1.Text.Replace(Resources.xmlheader, Resources.xmlbombe);
            textBox1.Text = textBox1.Text.Replace("test", "test &x3; &x7;");
        }; 
        
        h.hTool(toolStrip3, "register").Click += (s, s1) =>
        {
           
        };  

        }
        
      
        private void nullCmdToolStripMenuItem_Click(object sender, EventArgs e)
        {
               HTTPC h = new HTTPC();
               h.cmsSig(textBox1.Text.Trim());
        }

        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {
            foreach (string s in openFileDialog1.FileNames) {                                  
                new Check().setFile(s); 
            }
        }
        static BKUEDITOR singleton = null;

        public  static void debug(String t){
            singleton.debugBox.Text = t;       
        }
        public static void debug1(String s)
        {
            
            if (singleton.InvokeRequired) singleton.Invoke(new HTTPC.Procedure(debug1), new object[] { s }); 
            else  singleton.textBox2.Text = s;
        }
        
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            
             textBox1.Text=e.ToString();
             HTTPC.ziel = e.ToString();
        }  

        private void textBox3_TextChanged_1(object sender, EventArgs e)
        {
            HTTPC.ziel=textBox3.Text;
        }

        private void textBox3_Enter(object sender, EventArgs e)
        {
            textBox3.Text = HTTPC.ziel;
        }
             
        private void Form1_DragDrop(object sender, DragEventArgs e)
        {        
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {            
                string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
                foreach (string s in files)
                {
                    new Check().setFile(s); 
                }
            }       
            this.Invalidate();
        }

        private void Form1_DragEnter(object sender, DragEventArgs e)
        {       
            if (e.Data.GetDataPresent(DataFormats.FileDrop))            
                e.Effect = DragDropEffects.Copy;           
            else e.Effect = DragDropEffects.None;           
        }



    }
}
